import fs from 'node:fs'
import lodash from 'lodash'
import path from 'path';
import App from '../App.js';
export * from '../path.js';
import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
import { rootPath } from '../path.js';

let app = App.init({
    id: 'mmp',
    name: '丛雨原拓展'
})

app.reg({
    TeamDmg: {
        rule: /^(#)?队伍伤害.*$/,
        fn: gTD,
        name: "队伍伤害pro"
    },
    getqq_uid: {
        rule: /^(#)?我的uid.*$/,
        fn: guid,
        name: "qq-uid绑定关系查询"
    }
})
async function gTD(e) {
    e.reply("响应成功")
}
async function guid(e) {
    getdbgames();
}
async function getdbgames() {
    const db = await initDatabase();
  try {
    const row = await db.get('SELECT games FROM users WHERE id = ?', [3011991426]);
    console.log(row ? `Games: ${row.games}` : '用户不存在');
  } catch (error) {
    console.error('查询失败:', error);
  } finally {
    await db.close();
  }
}
async function initDatabase() {
    const db = await open({
      filename: path.join(rootPath, 'data', 'db', 'data.db'),
      driver: sqlite3.Database
    });
    await db.exec(`
      CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY,
        games TEXT
      )
    `);
  
    return db;
  }
export default app
